#ifndef __WIDGET_H__
#define __WIDGET_H__

#include <windows.h>
#include <stdint.h>

// define the EXPORT depending if the compiling is building for linking
// a dll, linking into a dll or linking as static
#ifdef BUILD_DLL
#define EXPORT __declspec(dllexport)
#elif BUILD_STATIC
#define EXPORT
#else
#define EXPORT __declspec(dllimport)
#endif

// define main function
#ifdef BUILD_STATIC
#define main(ARGC,ARGV) __main__(ARGC,ARGV)
#else
#define main(ARGC,ARGV) __main__(ARGC,ARGV);\
int WINAPI WinMain(HINSTANCE inst, HINSTANCE preinst, LPSTR cmdline,\
INT cmdshow){_WinMain(inst,preinst,cmdline,cmdshow,__main__);}\
int __main__(ARGC,ARGV)
#endif

#include "delegate.h"
#include "callback.h"

typedef struct widget_def
{
    // handle to its window
    HWND hwnd;
    // pointer to its parent
    struct widget_def *parent;
    // coordinates and size
    int32_t x;
    int32_t y;
    uint32_t width;
    uint32_t height;
    // string giving the widget name
    char *text;
    // pointer to the callback node
    callback_t *callback;
    // flag TRUE if the mouse cursor have enter the widget
    uint8_t mouse_entered_flag;
    // back buffer
    HDC memhdc;
    HBITMAP bmp;
    HBITMAP oldbmp;
    uint32_t *backbuf;
    // extended information
    void *ext;
} widget_t;

/*! Create a widget with the given coordinates and size
 *
 * \param parent: pointer to its parent, NULL if this is the parent.
 * \param x: coordinate
 * \param y: coordinate
 * \param width: size
 * \param height: size
 * \param backbuf_flag: set to TRUE if the widget users a backbuffer else FALSE
 * \return pointer to the created widget
 *
 * \note if the widget is a parent ie. (parent=NULL) giving a negative
 * value for x or y coordinate put the widget in center of the screen.
 */
EXPORT widget_t *create_widget(widget_t*,int32_t,int32_t,
                               uint32_t,uint32_t,uint8_t);

#endif // __WIDGET_H__

